package or.T0445;

import org.junit.jupiter.api.Test;

import java.util.ArrayDeque;
import java.util.Deque;

public class T0445 {


    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        Deque<Integer> stack1=new ArrayDeque<>();
        Deque<Integer> stack2=new ArrayDeque<>();
        while(l1!=null){
            stack1.push(l1.val);
            l1=l1.next;
        }
        while(l2!=null){
            stack2.push(l2.val);
            l2=l2.next;
        }
        ListNode l=null;
        int more=0;
        while (!stack1.isEmpty() || !stack2.isEmpty() || more>0){
            int a=stack1.isEmpty() ? 0:stack1.pop();
            int b=stack2.isEmpty() ? 0:stack2.pop();
            int sum=a+b+more;
            more=sum/10;
            ListNode t=new ListNode(sum%10);
            t.next=l;
            l=t;
        }
        return l;
    }
    @Test
    public void test() {



    }
}
